home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
FM Towns: Free Software Collection 10
/
FM Towns Free Software Collection 10.iso
/
ms_dos
/
tool
/
fapxtool
/
src
/
txl
/
txlcfexp.c
< prev
next >
Wrap
C/C++ Source or Header
|
1995-02-14
|
2KB
|
107 lines
/***************
*
* txlcfexp.c コマンドファイル展開
*/
#include "txl.h"
void readcf(char *fname, int *allocsize, int *usesize, int *paracnt)
{
int rsize, i;
FILE *fp;
struct stat stbuf;
char *baseptr = cfwork+*usesize;
if (*paracnt >= OP_MAX) {
return;
}
if (stat(fname, &stbuf)) {
return;
}
while (*usesize + stbuf.st_size > *allocsize) {
(*allocsize) += 1024;
cfwork = realloc(cfwork, *allocsize);
}
if ((fp = fopen(fname, "rt")) == NULL) {
return;
}
rsize = fread(baseptr, 1, stbuf.st_size, fp);
*usesize += rsize;
*(cfwork + *usesize) = NUL;
(*usesize)++;
for (i = 0; i < rsize; i++) {
if (*(baseptr + i) > ' ') { /* not space ? */
if (*(baseptr + i) == '@') {
log_bufptr = baseptr + i + 1; /* log_bufptr is temporary */
while (*log_bufptr > ' ') log_bufptr++;
*log_bufptr = NUL;
readcf((baseptr + i + 1), allocsize, usesize, paracnt);
}
else {
cfptr[*paracnt] = baseptr+i;
}
if (*(baseptr + i) == 0x22) { /* double quote */
cfptr[*paracnt]++;
i++;
while (*(baseptr + i) != 0x22) {
i++;
if (*(baseptr + i) == NUL) {
return;
}
}
*(baseptr + i) = NUL;
}
else {
while (*(baseptr + i) > ' ') i++;
}
(*paracnt)++;
if (*paracnt >= OP_MAX) {
return;
}
}
*(baseptr + i) = NUL;
}
}
void cfexpand(int count, char *val[])
{
int i, allocsize = 0, usesize = 0, paracnt = 0;
int expandflg = FALSE;
for (i = 0; i < count; i++) { /* プレスキャン */
if (val[i][0] == '@') {
expandflg = TRUE;
}
}
if (!expandflg) {
swchk(count, val);
Exit(0);
}
allocsize = 1024;
cfwork = malloc(1024);
for (i = 0; i < count; i++) { /* 実スキャン */
if (val[i][0] == '@') {
readcf(&(val[i][1]), &allocsize, &usesize, ¶cnt);
}
else {
cfptr[paracnt] = val[i];
paracnt++;
}
if (paracnt >= OP_MAX) {
free(cfwork);
Exit(1);
}
}
swchk(paracnt, cfptr);
Exit(0);
}